package Operation;
import Class.ClassMate;

import Personnel.Student;

import java.util.Scanner;

public class DelOperation implements Ioperation {
    @Override
    public void work(ClassMate classmate) {
        System.out.println("删除学生");
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入要删除的学生的名字");
        String name = scanner.nextLine();
        int currentSize = classmate.getClassSize();

        int delIndex = -1;
        for (int i = 0; i < currentSize; i++) {
            Student student = classmate.getStudent(i);
            if(student.getName().equals(name)){
                delIndex = i;
                break;
            }
        }
        if (delIndex == -1){
            System.out.println("没有要删除的学生");
            return;
        }

        for (int i = delIndex; i <currentSize ; i++) {
            Student student = classmate.getStudent(i + 1);
            classmate.setStudent(i,student);
        }
        classmate.setStudent(currentSize,null);
        classmate.setClassSize(currentSize - 1);
        System.out.println("删除成功！！");
    }
}
